home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / var / lib / dpkg / info / samba-common.postinst < prev    next >
Text File  |  2008-10-10  |  4KB  |  148 lines

  1. #!/bin/sh
  2. #
  3. #
  4.  
  5. set -e
  6.  
  7. # Do debconf stuff here
  8. . /usr/share/debconf/confmodule
  9.  
  10. TEMPDIR=/var/run/samba/upgrades
  11. NEWFILE=$TEMPDIR/smb.conf
  12. CONFIG=/etc/samba/smb.conf
  13.  
  14. # ------------------------- Debconf questions start ---------------------
  15.  
  16. configure_smb_conf() {
  17.     local CONFIG
  18.     CONFIG="$1"
  19.  
  20.     # Is the user configuring with debconf, or he/she prefers
  21.     # swat/manual config?
  22.     db_get samba-common/do_debconf || true
  23.     if [ "${RET}" != "true" ]; then
  24.         return 0
  25.     fi
  26.  
  27.     # Get workgroup name
  28.     db_get samba-common/workgroup || true
  29.     WORKGROUP="${RET}"
  30.  
  31.     # Oh my GOD, this is ugly.  Why would anyone put these
  32.     # characters in a workgroup name?  Why, Lord, why???
  33.     WORKGROUP=`echo $WORKGROUP | \
  34.                sed -e's/\\\\/\\\\\\\\/g
  35.                       s#/#\\\\/#g
  36.                       s/&/\\\&/g
  37.                       s/\\\$/\\\\\\\$/g'`
  38.  
  39.     sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
  40.         /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
  41.             s/^\([[:space:]]*\)workgroup[[:space:]]*=.*/\1workgroup = ${WORKGROUP}/i" \
  42.         "$CONFIG"
  43.  
  44.     # Encrypt passwords?
  45.     db_get samba-common/encrypt_passwords || true
  46.     ENCRYPT_PASSWORDS="${RET}"
  47.  
  48.     sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
  49.         /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
  50.                 s/^\([[:space:]]*\)encrypt passwords[[:space:]]*=.*/\1encrypt passwords = ${ENCRYPT_PASSWORDS}/i" \
  51.         "$CONFIG"
  52.  
  53.     # Install DHCP support
  54.     db_get samba-common/dhcp
  55.     if [ "$RET" = true ] && \
  56.        ! grep -q dhcp.conf "$CONFIG"
  57.     then
  58.         sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
  59.             /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ {
  60.                 /wins server[[:space:]]*=/a \\
  61. \\
  62. # If we receive WINS server info from DHCP, override the options above. \\
  63.    include = /etc/samba/dhcp.conf
  64. }" "$CONFIG"
  65.     elif [ "$RET" != true ]; then
  66.         sed -i -e '
  67.         /^#[[:space:]]*If we receive WINS server info from DHCP, override the options above/d
  68.         /^#*[[:space:]]*include[[:space:]]*=[[:space:]]*\/etc\/samba\/dhcp.conf/,/[^[:space:]]/ {
  69.             /^#*[[:space:]]*include[[:space:]]*=[[:space:]]*\/etc\/samba\/dhcp.conf/d
  70.             /^[[:space:]]*$/d
  71.         }' "$CONFIG"
  72.     fi
  73.  
  74.     if [ -n "$2" ] && dpkg --compare-versions "$2" lt 3.0.23b-2 \
  75.        && grep -qi "^[[:space:]]*passdb backend[[:space:]]*=.*guest" "$CONFIG"
  76.     then
  77.         sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
  78.             /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
  79.                     s/^\([[:space:]]*passdb backend[[:space:]]*=[^,]*\),\?[[:space:]]*guest[[:space:]]*$/\1/i" \
  80.             "$CONFIG"
  81.     fi
  82. }
  83.  
  84.  
  85. if [ -e "$CONFIG" ]; then
  86.     configure_smb_conf "$CONFIG"
  87. fi
  88.  
  89. mkdir -p "$TEMPDIR"
  90.  
  91. if [ -n "$2" ] && dpkg --compare-versions "$2" lt 3.0.28-3; then
  92.     if dpkg --compare-versions "$2" lt 3.0.26a-1 && [ "$2" != "${2%ubuntu*}" ]
  93.     then
  94.         base=dapper
  95.     elif [ "$2" != "${2%ubuntu*}" ]
  96.     then
  97.         if [ -e "${CONFIG}" ]
  98.         then
  99.             if grep -q ';   winbind enum groups = yes' ${CONFIG}
  100.             then
  101.                 base=gutsy
  102.             elif grep -q '# /usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/ServerType.html' ${CONFIG}
  103.             then
  104.                 base=feisty
  105.             else
  106.                 base=dapper
  107.             fi
  108.         else
  109.             base=gutsy
  110.         fi
  111.     else
  112.         base=etch
  113.     fi
  114.  
  115.     TEMPLATE=/usr/share/samba/smb.conf.${base}
  116.  
  117.     cp "$TEMPLATE" "$NEWFILE"
  118.     configure_smb_conf "$NEWFILE"
  119.  
  120.     if [ -e "$CONFIG" ]; then
  121.         sed -e '1,/^[;#[:space:]]*\[cdrom\]/ { d }
  122.             1,/^[[:space:]]*\[/ { /^[^[]/d; /^$/d }
  123.         ' "$CONFIG" >> "$NEWFILE"
  124.     fi
  125.  
  126.     ucf --three-way --debconf-ok "$NEWFILE" "$CONFIG"
  127. fi
  128.  
  129. cp /usr/share/samba/smb.conf "$NEWFILE"
  130. configure_smb_conf "$NEWFILE"
  131.  
  132. if [ -e "$CONFIG" ]; then
  133.     sed -e '1,/^[;#[:space:]]*\[cdrom\]/ { d }
  134.         1,/^[[:space:]]*\[/ { /^[^[]/d; /^$/d }
  135.     ' "$CONFIG" >> "$NEWFILE"
  136. fi
  137.  
  138. ucf --three-way --debconf-ok "$NEWFILE" "$CONFIG"
  139. ucfr samba-common "$CONFIG"
  140.  
  141. chmod a+r "$CONFIG"
  142.  
  143. # ------------------------- Debconf questions end ---------------------
  144.  
  145. db_stop
  146.  
  147.  
  148.